package com.jwthhealth_pub.old.sportfitness.view.adapter;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jwthhealth_pub.R;
import com.jwthhealth_pub.old.sportfitness.module.SprotCourseInfoModule;
import com.jwthhealth_pub.old.sportfitness.view.SportCourseListActivity;
import com.jwthhealth_pub.old.sportfitness.view.adapter.inner.SprotItemBodyInnerAdapter;

/**
 * Created by Administrator on 2017/1/6.
 */
public class SportCourseListAdapter extends RecyclerView.Adapter {

    private SportCourseListActivity activity;
    SprotCourseInfoModule.DataBean.VideoListBean data;

    public SportCourseListAdapter(SportCourseListActivity sportCourseListActivity, SprotCourseInfoModule.DataBean.VideoListBean videoListBean) {
        this.activity = sportCourseListActivity;
        this.data = videoListBean;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (viewType == ITEM_TYPE.ITEM_HEAD.ordinal()) {
            return new HeadViewHolder(LayoutInflater.from(activity).inflate(R.layout.item_sport_course_list_head, parent, false));
        } else if (viewType == ITEM_TYPE.ITEM_BODY.ordinal()) {
            return new BodyViewHolder(LayoutInflater.from(activity).inflate(R.layout.item_sport_course_list_body, parent, false));
        } else {
            return new FootViewHolder(LayoutInflater.from(activity).inflate(R.layout.item_sport_course_list_foot, parent, false));
        }
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (position == 0) {
            HeadViewHolder headViewHolder = (HeadViewHolder) holder;
            headViewHolder.title.setText(data.getName());
        } else if (position == 1) {
            BodyViewHolder bodyViewHolder = (BodyViewHolder) holder;
            bodyViewHolder.rv.setLayoutManager(new LinearLayoutManager(activity));
            bodyViewHolder.rv.setAdapter(new SprotItemBodyInnerAdapter(activity, data.getMain_desc()));
        } else {
            FootViewHolder footViewHolder = (FootViewHolder) holder;
//            footViewHolder.horRv.setAdapter(new SportItemFootInnerAdapter(data.));
        }

    }

    @Override
    public int getItemCount() {
        return 3;
    }

    @Override
    public int getItemViewType(int position) {
        if (position == 0){
            return ITEM_TYPE.ITEM_HEAD.ordinal();
        } else if (position == 1){
            return ITEM_TYPE.ITEM_BODY.ordinal();
        } else {
            return ITEM_TYPE.ITEM_FOOT.ordinal();
        }
    }

    private class HeadViewHolder extends RecyclerView.ViewHolder{

        private TextView title;
        private SurfaceView surfaceView;

        public HeadViewHolder(View itemView) {
            super(itemView);
            title = (TextView) itemView.findViewById(R.id.head_title);
            surfaceView = (SurfaceView) itemView.findViewById(R.id.head_surfaceview);
        }
    }

    class BodyViewHolder extends RecyclerView.ViewHolder{

        RecyclerView rv;

        public BodyViewHolder(View itemView) {
            super(itemView);
            rv = (RecyclerView) itemView.findViewById(R.id.body_item_rv);
        }
    }

    class FootViewHolder extends RecyclerView.ViewHolder{

        TextView describe;
        RecyclerView horRv, verRv;

        public FootViewHolder(View itemView) {
            super(itemView);
            itemView.findViewById(R.id.foot_describe);

        }
    }

    private enum ITEM_TYPE {
        ITEM_HEAD, ITEM_BODY, ITEM_FOOT;
    }
}
